<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
include_once "common.php";

class cs_parameter {

    function cs_parameter() {
        global $baseinfo_c;
        $baseinfo_c = new baseinfo_common();
    }

    function select($code="") {
        global $baseinfo_c;
        if ($code == "") {
            $strSql = "SELECT parameter_code,parameter_value,description FROM cs_parameter;";
        } else {
            $strSql = "SELECT parameter_code,parameter_value,description FROM cs_parameter WHERE parameter_code='" . $code . "';";
        }
        $handle = $baseinfo_c->execSql($strSql);
        return $handle;
    }

    function update($code, $value) {
        global $baseinfo_c;
        $strSql = "UPDATE cs_parameter SET parameter_value='" . trim($value) . "' WHERE parameter_code='" . trim($code) . "';";
        $handle = $baseinfo_c->execSql($strSql);
    }

    function getValueByCode($code) {
        global $baseinfo_c;
        $strSql = "SELECT parameter_code,parameter_value,description FROM cs_parameter WHERE parameter_code='" . $code . "';";
        $handle = $baseinfo_c->execSql($strSql);
        if (($row = mysql_fetch_object($handle)) != null) {
            return $row->parameter_value;
        } else {
            return "";
        }
    }

    //--------------------------------------------------------------------------
    function getUploadFileSize() {
        return intval($this->getValueByCode("uploadFileSize")) * 1024;
    }

    function getUploadPath() {
        //              /upload
//        $var = $this->getValueByCode("uploadPath");
//        $len = strlen($var);
//        if ($len > 0) {
//            if (substr($var, 0, 1) != "/") {
//                $var = "/" . $var;
//            }
//            $len = strlen($var);
//            if (substr($var, $len - 1, 1) == "/") {
//                $var = substr($var, 0, $len - 1);
//            }
//        } else {
//            $var = "";
//        }
//        return $var;
        return $this->getPath("uploadPath");
    }

    function getPath($p) 
    {
        $var = $this->getValueByCode($p); //eg: "uploadPath"
        $len = strlen($var);
        if ($len > 0) 
        {
            if (substr($var, 0, 1) != "/") {
                $var = "/" . $var;
            }
            $len = strlen($var);
            if (substr($var, $len - 1, 1) == "/") {
                $var = substr($var, 0, $len - 1);
            }
        } 
        else 
        {
            $var = "";
        }
        return $var;
    }

    function getDefaultTime() {
        return $this->getValueByCode("defaultTime");
    }

    function getPageSize() {
        return intval($this->getValueByCode("pageSize"));
    }

    function getDownloadPath() {
        //              /download/
        $var = $this->getValueByCode("downloadPath");
        $len = strlen($var);
        if ($len > 0) {
            if (substr($var, 0, 1) != "/") {
                $var = "/" . $var;
            }
            $len = strlen($var);
            if (substr($var, $len - 1, 1) != "/") {
                $var = $var . "/";
            }
        } else {
            $var = "";
        }
        return $var;
    }

    function getHomePage() {
        return $this->getValueByCode("homePage");
    }

    function getXNumberDays() {
        return $this->getValueByCode("xNumberDays");
    }

    function getDbTablePrefix() {
        return $this->getValueByCode("dbTablePrefix");
    }

    function getimgUploadPath() {
        //return $this->getValueByCode("imgUploadPath");
        return $this->getPath("imgUploadPath");
    }

    function getPictureExtName() {
        return $this->getValueByCode("pictureExtName");
    }

    function getPictureBrowerFileType() {
        return $this->getValueByCode("pictureBrowerFileType");
    }

    function getPicBigHeight() {
        return $this->getValueByCode("pic_big_height");
    }

    function getPicBigWidth() {
        return $this->getValueByCode("pic_big_width");
    }

    function getPicMiddleHeight() {
        return $this->getValueByCode("pic_median_height");
    }

    function getPicMiddleWidth() {
        return $this->getValueByCode("pic_median_width");
    }

    function getPicSmallHeight() {
        return $this->getValueByCode("pic_small_height");
    }

    function getPicSmallWidth() {
        return $this->getValueByCode("pic_small_width");
    }

    function getFlashUploadPath() {
        //return $this->getValueByCode("flashUploadPath");
        return $this->getPath("flashUploadPath");
    }

    function getFlashExtName() {
        return $this->getValueByCode("flashExtName");
    }

    function getFlashBrowerFileType() {
        return $this->getValueByCode("flashBrowerFileType");
    }

    function getFlashFileSize() {
        //return $this->getValueByCode("flashFileSize");
        return intval($this->getValueByCode("flashFileSize")) * 1024;
    }

    function getPicAdFileSize() {
        //return $this->getValueByCode("pic_ad_fileSize");
        return intval($this->getValueByCode("pic_ad_fileSize")) * 1024;
    }

}
?>
